package com.vecspace;

import java.io.IOException; 

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.vecspace.saas.SaasTenantThreadHolder;
import com.vecspace.utils.log.HttpRequestLogThreadLocal;
import com.vecspace.web.HttpContextThreadLocal;
/**1、清除所有LocalThread的数据（因为web请求是从线程池中获取的线程，会保留上一个线程中LocalThread的的数据）
 */
public class FirstFilter implements Filter{
	 
	@Override
	public void destroy() {
		
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain chain) throws IOException, ServletException {
		//testLogin();
		HttpServletRequest request = (HttpServletRequest) req;
		HttpServletResponse response = (HttpServletResponse) res;
		
		//1、清除所有LocalThread的数据（因为web请求是从线程池中获取的线程，会保留上一个线程中LocalThread的的数据）
		HttpContextThreadLocal.remove();
		HttpRequestLogThreadLocal.remove();
		//SqlExecuteLogsThreadLocal.remove();
		SaasTenantThreadHolder.remove();
		
		chain.doFilter(request, response);
	}

	@Override
	public void init(FilterConfig config) throws ServletException {
		
	}

}
